/**
 * 
 */
package com.shequan.shequan.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.shequan.common.bean.ResultDataStruct;
import com.shequan.search.bean.bo.UserDetailBean;
import com.shequan.shequan.bean.bo.FamousShequanDetail;
import com.shequan.shequan.bean.bo.MemberDetail;
import com.shequan.shequan.bean.bo.QryShequanMember;
import com.shequan.shequan.bean.pojo.Shequan;
import com.shequan.shequan.dao.FamousShequanDAO;
import com.shequan.shequan.dao.ShequanDAO;
import com.shequan.shequan.dao.ShequanUserRltDAO;
import com.shequan.shequan.service.ShequanService;
import com.shequan.user.dao.UserInfoDAO;

/**
 * <P>
 * Copyright 2012.
 * </p>
 * <P>
 * All Rights Reserved.
 * </p>
 * 
 * @author YuJF
 * @version 1.0, 2012-3-14
 * @see com.shequan.shequan.service.impl.ShequanServiceImpl
 * @since 1.0
 */
public class ShequanServiceImpl implements ShequanService {
	private ShequanDAO shequanDao;
	private ShequanUserRltDAO shequanUserRltDAO;
	private UserInfoDAO userInfoDAO;
	private FamousShequanDAO famousShequanDAO;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.shequan.shequan.service.ShequanService#queryShequanByUserName(java
	 * .lang.String)
	 */
	public ResultDataStruct<List<Shequan>> queryShequanByUserId(int userId) {
		ResultDataStruct<List<Shequan>> rds = new ResultDataStruct<List<Shequan>>();
		List<Shequan> shequans = shequanDao.selectByUserId(userId);
		rds.setData(shequans);
		rds.setBusiSuccess(true);
		rds.setSuccess(true);
		return rds;
	}

	public QryShequanMember queryShequanMemberByPage(int shequanId, int page, int limit) {
		QryShequanMember shequanMember = new QryShequanMember();
		// 查询用户成员数量
		long totalCount = shequanUserRltDAO.queryUserCountByShequanId(shequanId);
		List<MemberDetail> memberList = new ArrayList<MemberDetail>();
		if (totalCount > 0) {
			// 查询成员列表
			List<UserDetailBean> userDetailList = userInfoDAO.queryUserDetailByPage(shequanId, page, limit);
			MemberDetail member = null;
			for (UserDetailBean userDetail : userDetailList) {
				member = (MemberDetail) userDetail;
				// 分别查询用户社圈信息
				List<Shequan> shequanList = shequanDao.queryShequanList(member.getUserId());
				member.setShequanList(shequanList);
				memberList.add(member);
			}
		}

		shequanMember.setMemberList(memberList);
		shequanMember.setTotal(totalCount);
		return shequanMember;
	}

	public List<FamousShequanDetail> queryAllFamousShequanDetail() throws Exception {
		// List<FamousShequanDetail> famousShequanDetails = new
		// ArrayList<FamousShequanDetail>();
		// FamousShequanDetail fsd = new FamousShequanDetail();
		// fsd.setActCount(10);
		// fsd.setAreaId(12);
		// fsd.setShequanName("测试社圈");
		// fsd.setMembersCount(10);
		// fsd.setShequanId(1);
		// fsd.setShequanDesc("一群未来准医生同历生老病死，与疾病日夜拼...");
		// fsd.setShequanLogo1("/res/theme/default/images/temp/user_1.gif");
		// famousShequanDetails.add(fsd);
		// famousShequanDetails.add(fsd);
		// famousShequanDetails.add(fsd);
		// famousShequanDetails.add(fsd);
		// return famousShequanDetails;
		return famousShequanDAO.queryAllFamousShequanDetail();
	}

	public void setShequanDao(ShequanDAO shequanDao) {
		this.shequanDao = shequanDao;
	}

	/**
	 * @param shequanUserRltDAO
	 *            the shequanUserRltDAO to set
	 */
	public void setShequanUserRltDAO(ShequanUserRltDAO shequanUserRltDAO) {
		this.shequanUserRltDAO = shequanUserRltDAO;
	}

	/**
	 * @param userInfoDAO
	 *            the userInfoDAO to set
	 */
	public void setUserInfoDAO(UserInfoDAO userInfoDAO) {
		this.userInfoDAO = userInfoDAO;
	}

	/**
	 * @param famousShequanDAO
	 *            the famousShequanDAO to set
	 */
	public void setFamousShequanDAO(FamousShequanDAO famousShequanDAO) {
		this.famousShequanDAO = famousShequanDAO;
	}

}
